#include<stdio.h>/*提前自主完成，有一些代码不是老师的代码 */
#include<conio.h>
#include<iostream>
#include<iomanip>
#include<graphics.h>
using namespace std;
float random_height[3] = { 135,160,185 };
float random_width[4] = { 40,50,70,85 };
float random_v[5] = { 5,6,7,8,9 };

float random_change[2] = { 10,15 };
int main()
{
    int length = 115;
    int Judge1, Judge2;
    int k, m, n;
    k = 0, m = 0, n = 0;
    float width, height, gravity;//定义浮点型变量，为了任意时候想改参数时更加easy
    float radiu = 20;
    width = 600;height = 400, gravity = 0.5;
    float ball_x = width / 4;//定小球在左方屏幕四分之一处
    float ball_y = height - radiu;//定义初始高度为小球上边缘与边框下方相切
    float ball_vy = 0;//定义初始速度为0
    initgraph(width, height);//插入屏幕
    float rect_left, rect_height, rect_width;
    float v_rect;
    rect_width = 50, rect_left = 550, v_rect = 5, rect_height = 200;

    int iCount = 1;
    int Counting = 0;
    while (1)//死循环
    {


        v_rect = random_v[n];
        ball_vy += gravity;//速度不断以G值增加
        ball_y += ball_vy;//小球竖直方向的位移不断以小球速度增加
        if (ball_y < 0)//保证小球不超过上边界
            ball_y = 0;
        if (ball_y >= height - radiu)//判断，保证小球不超过下边界
        {
            ball_y = height - radiu;
        }


        if (_kbhit())//空格给予小球向上的速度
        {
            char input = _getch();
            if (input == ' ')
                ball_vy = -7;
        }

        rect_left -= v_rect;
        if (rect_left < -rect_width)//跳过小球计分,重置方块
        {
            Counting++;
            k++, m++, n++;
            rect_left = 600;
            Counting++;
            rect_width = random_width[k];
            rect_left = 600 - rect_width;
            rect_height = random_height[k];

        }
        Judge1 = (rect_left <= ball_x + radiu && ball_y + radiu >= rect_height && ball_x + radiu
            < rect_left + rect_width) || rect_left < ball_x + radiu && ball_y + radiu
            >= rect_height && rect_left + rect_width >= ball_x - radiu;
        Judge2 = (rect_left <= ball_x + radiu && ball_y - radiu <= random_height[k] - length && ball_x + radiu <= rect_left + rect_width);

        if (Judge1 == 1 || Judge2 == 1)//判断违规
        {

            cout << "you lose" << endl << "you have got " << Counting << " points" << endl;
            goto label1;
        }
        if (k == 2)//控制数组变量
            k = 0;
        if (m == 3)
            m = 0;
        if (n == 4)
            n = 0;

        cleardevice();//清屏
        fillrectangle(rect_left, rect_height, rect_left + rect_width, 400);//输入方块
        fillrectangle(rect_left, random_height[k] - length, rect_left + rect_width, 0);
        fillcircle(ball_x, ball_y, radiu);//输入小球
        Sleep(20);



    }
label1:
    _getch();
    closegraph();

}